﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace SearchAssembly
{
    /// <summary>
    /// Welcome page
    /// </summary>
    public partial class frmWelcome : SearchAssembly.frmMaster
    {
        /// <summary>
        /// Constructor
        /// </summary>
        public frmWelcome()
        {
            InitializeComponent();
        }

        private void frmWelcome_Load(object sender, EventArgs e)
        {
            // Load page data
            if (this.pageData != null)
            {
                WizardData.PageDataRow firstRow = (WizardData.PageDataRow)this.pageData.Rows[0];
                txtWelcomeNote.Text = firstRow.Value;
            }
            else
            {
                txtWelcomeNote.Text = GetWelcomeText();
            }
        }

        private string GetWelcomeText()
        {
            string welcomeMSG = "Welcome to Assembly Search Tool";

            try
            {
                welcomeMSG = File.ReadAllText(string.Concat(Environment.CurrentDirectory, "\\", "PreRequisites\\Welcome.txt"));
            }
            catch (FileNotFoundException)
            {
                // Ignore
            }
            catch (DirectoryNotFoundException)
            {
                // Ignore
            }

            return welcomeMSG;
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            SavePage();
            WizardHelper.LoadPage(this, PageType.AssemblySearch);
        }
        
        private void SavePage()
        {
            this.pageData = new WizardData.PageDataDataTable();

            WizardData.PageDataRow newPageDataRow = this.pageData.NewPageDataRow();
            newPageDataRow.Key = "WelcomeMSG";
            newPageDataRow.Value = txtWelcomeNote.Text;
            this.pageData.AddPageDataRow(newPageDataRow);

            WizardPage thisPage = new WizardPage();
            thisPage.typeOfPage = PageType.Welcome;
            thisPage.pageData = this.pageData;

            WizardHelper.SavePage(thisPage);
        }
    }
}
